package com.lznb.cloud.controller.frant;

import com.lznb.cloud.entity.News;
import com.lznb.cloud.entity.NewsCategory;
import com.lznb.cloud.entity.Users;
import com.lznb.cloud.service.NewsCategoryService;
import com.lznb.cloud.service.NewsService;
import com.lznb.cloud.utils.JsonResultExt;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 新闻表
 *
 * @author mzy
 * @email 1992lcg@163.com
 * @date ${datetime}
 */

@Controller
@RequestMapping("/f/newsController")
public class FNewsController {
    @Autowired
    Configuration configuration;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private NewsService newsService;

    @Autowired
    private NewsCategoryService newsCategoryService;

    /**
     * 查询案例
     * @param newsId
     * @param model
     * @return
     */
    @GetMapping("/tocaseShow")
    public String tocaseShow(String newsId, Model model) {
        News news = newsService.getNews(newsId);
        model.addAttribute("news", news);
        news.setNewsReadingnumber(news.getNewsReadingnumber()+1);
        newsService.update(news);
        return "/frant/caseshow";
    }

    /**
     * 查询关于我们
     * @param model
     * @return
     */
    @GetMapping("/toAbout")
    public String toAbout(Model model) {
        List<News> about_diy1 = newsService.findByCategory("6abd627d3f4e42c5a4f244fd9336cb89");
        List<News> about_diy2 = newsService.findByCategory("ee51314e983f407995ef6bf6bf452282");
        List<News> about_diy3 = newsService.findByCategory("025f9459c3644f66b329059f18c8eb71");
        List<News> about_diy4 = newsService.findByCategory("9c5cbb0487c84e2fa60a4f136f9cd7c1");
        List<News> team_con = newsService.findByCategory("5aced0d7ce624ba890a443bf9341eaa8");
        model.addAttribute("about_diy1",about_diy1);
        model.addAttribute("about_diy2",about_diy2);
        model.addAttribute("about_diy3",about_diy3);
        model.addAttribute("about_diy4",about_diy4);
        model.addAttribute("team_con",team_con);
        return "/frant/about";
    }

    /**
     * 联系我们
     * @param model
     * @return
     */
    @GetMapping("/toContact")
    public String toContact(Model model) {
        List<News> contact = newsService.findByCategory("a691f59cb6964b5fb9af5c943ea9845d");
        model.addAttribute("contact",contact);
        return "/frant/contact";
    }
}
